<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>代理模式</title>
</head>
<body>
<div id="father">
    <a href="">1</a>
    <a href="">2</a>
    <a href="">3</a>
    <a href="">4</a>
    <a href="">5</a>
    <a href="">6</a>
</div>
<script>
    const father = document.getElementById('father')
    father.addEventListener('click', function(e) {
        if(e.target.tagName === 'A') {
            e.preventDefault()
            alert(`我是${e.target.innerText}`)
        }
    })
</script>
<script>
    const addAll = function() {
        console.log('计算了一次')
        let result = 0
        const len = arguments.length
        for (let i = 0; i < len; i++) {
            result+= arguments[i]
        }
        return result
    }

    const proxyAddAll = (function () {
        const resultCache = {}
        return function() {
            const args = Array.prototype.join.call(arguments,',')
            if (args in resultCache) {
                return resultCache[args]
            }
            return resultCache[args] = addAll(...arguments)
        }
    })()
    console.log(proxyAddAll(1,2,3,4,5,6))
    console.log(proxyAddAll(1,2,3,4,5,6))
</script>
</body>
</html>
